package com.property.controller;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.property.biz.InformBiz;
import com.property.biz.InformTargetBiz;
import com.property.entity.Inform;
import com.property.entity.InformTarget;
import com.property.entity.Management;
import com.property.entity.Owner;

@Controller
@RequestMapping("/main")
public class InformController {
	
	@Autowired
	private InformBiz informBiz;
	@Autowired 
	private InformTargetBiz informTargetBiz;
	
	@RequestMapping("/in")
	@ResponseBody
	public String inform(@RequestParam("checked")String []checked,String radio,String text,HttpSession session){
		System.out.println("--"+checked.length);
		Management management=(Management) session.getAttribute("management");
		Management management2=new Management();
		management2.setId(management.getId());
		Inform inform=new Inform();
		inform.setType(radio);
		inform.setManagement(management2);
		inform.setContent(text);
		if(checked.length>=0){
			 informBiz.add(inform);
			 InformTarget informTarget=new InformTarget();
			 Inform inform2=new Inform();
			 inform2.setId(inform.getId());
			 informTarget.setInform(inform2);
		for(int i=0;i<checked.length;i++){
			Owner owner=new Owner();
			owner.setId(Integer.parseInt(checked[i]));
			informTarget.setOwner(owner);
			informTargetBiz.addInTarget(informTarget);
		}
		}
		return "redirect:community";
	}
}
